//
//  AppDelegate.swift
//  WeIBo
//
//  Created by 苏文潇 on 2017/3/4.
//  Copyright © 2017年 苏文潇. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        
//        测试解挡获取数据
//      let userAccount = XGTokenUserAccount.loadUserAccount()
//       print(userAccount?.access_token)
        NotificationCenter.default.addObserver(self, selector: #selector(switchRootVc(noti:)), name: NSNotification.Name(SwitchNotification), object: nil)
        
//        创建window
        window = UIWindow(frame: UIScreen.main.bounds)
//        创建根视图控制器
        let rootVc = XGTabBarViewController()
        
//        设置根视图控制器
        window?.rootViewController = rootVc
//        显示
        window?.makeKeyAndVisible()
//        给window添加背景图(防止在push的时候出现阴影)
        window?.backgroundColor = UIColor.white
        
        return true
    }

//    监听通知的方法
    @objc private func switchRootVc(noti: NSNotification)
    {
        let obj = noti.object as? UIViewController
        
        if obj is XGOAuthController {
            window?.rootViewController = XGWelcomeViewController()
        }else{
            window?.rootViewController = XGTabBarViewController()
        }
    }
   
    
//    MARK:  标准写法注册通知和移除通知必须成对
    deinit {
        NotificationCenter.default.removeObserver(self)
    }
    

    


}

